package main.com.oaer.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import main.com.oaer.common.HibernateDaoUtil;
import main.com.oaer.dao.RoleDao;
import main.com.oaer.model.Role;

@Repository
public class RoleDaoImpl implements RoleDao {

	@Autowired
	HibernateDaoUtil hibernateDaoUtil;
	
	@Override
	public Role load(Long id) {
		return hibernateDaoUtil.load(Role.class, id);
	}
	
	@Override
	public void add(Role role) {
		hibernateDaoUtil.save(role);
	}

	@Override
	public List<Role> findRoles(){
		String hql = "from Role";
		return hibernateDaoUtil.findListByHQL(hql);
	}

	@Override
	public void delete(Role role) {
		if(role!=null){
			hibernateDaoUtil.delete(role);
		}
	}

	@Override
	public void update(Role role) {
		if(role!=null) {
		    hibernateDaoUtil.update(role);
		}
	}

	@Override
	public List<Map<String, Object>> findRolesMap() {
		String hql = "select " +
				" role.roleId as roleId," +
				" role.name as name," +
				" role.description as description " +
				" from Role role";
		return hibernateDaoUtil.findListMapByHQL(hql, null);
	}

}
